import os
import django
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "baoxian.settings")
django.setup()


from insurance.models import InsuranceInfo
from pydantic import BaseModel, Field
from langchain.tools import StructuredTool


class CheckUserInsuranceSchema(BaseModel):
    id_number: str = Field(..., description="身份证号，18位")

def check_user_insurance_func(id_number: str) -> str:
    exists = InsuranceInfo.objects.filter(id_number=id_number).exists()
    if not exists:
        return "未查询到用户保险信息，不能理赔"
    return f"用户 {id_number} 已购买保险，可进入下一步"

check_user_insurance = StructuredTool.from_function(
    func=check_user_insurance_func,
    name="check_user_insurance",
    description="根据身份证号查询用户是否购买过保险。",
    args_schema=CheckUserInsuranceSchema,
)

